package labuladong.chapter0;

public class DoublyListNode {
    int val;
    DoublyListNode next;

    DoublyListNode prev;

    DoublyListNode(int val) {
        this.val = val;
    }

    /**
     * 通过数组创建双链表
     */
    public static DoublyListNode createDoublyLinkedList(int[] array) {
        if (array == null || array.length == 0) {
            return null;
        }
        DoublyListNode head = new DoublyListNode(array[0]);
        head.prev = null;
        DoublyListNode currentNode = head;
        for (int i = 1; i < array.length; i++) {
            DoublyListNode next = new DoublyListNode(array[i]);
            currentNode.next = next;
            next.prev = currentNode;
            currentNode = next;
        }
        return head;
    }
}
